//-----------------------------------------------------------------------
// <copyright file="a_products_specs_detDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_products_specs_detDAOBase
    {
        #region Common methods
        public virtual a_products_specs_det Createa_products_specs_detFromReader(IDataReader reader)
        {
            a_products_specs_det item = new a_products_specs_det();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("Id"))) item.Id = (int)reader["Id"];
                if (!reader.IsDBNull(reader.GetOrdinal("Specsheetid"))) item.Specsheetid = (int)reader["Specsheetid"];
                if (!reader.IsDBNull(reader.GetOrdinal("Specname"))) item.Specname = (string)reader["Specname"];
                if (!reader.IsDBNull(reader.GetOrdinal("Value1"))) item.Value1 = (string)reader["Value1"];
                if (!reader.IsDBNull(reader.GetOrdinal("Value2"))) item.Value2 = (string)reader["Value2"];
                if (!reader.IsDBNull(reader.GetOrdinal("Value3"))) item.Value3 = (string)reader["Value3"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_products_specs_det methods
            
        public virtual void Createa_products_specs_det(a_products_specs_det a_products_specs_det)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_products_specs_det_ins");
                
                database.AddInParameter(dbCommand, "@Specsheetid", DbType.Int32, a_products_specs_det.Specsheetid);
                database.AddInParameter(dbCommand, "@Specname", DbType.AnsiString, a_products_specs_det.Specname);
                database.AddInParameter(dbCommand, "@Value1", DbType.AnsiString, a_products_specs_det.Value1);
                database.AddInParameter(dbCommand, "@Value2", DbType.AnsiString, a_products_specs_det.Value2);
                database.AddInParameter(dbCommand, "@Value3", DbType.AnsiString, a_products_specs_det.Value3);
                database.AddOutParameter(dbCommand, "@Id", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_products_specs_det.Id = (int)database.GetParameterValue(dbCommand, "@Id");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_products_specs_det methods
        
        public virtual void Updatea_products_specs_det(a_products_specs_det a_products_specs_det)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_products_specs_det_upd");            
                
                database.AddInParameter(dbCommand, "@Id", DbType.Int32, a_products_specs_det.Id);
                database.AddInParameter(dbCommand, "@Specsheetid", DbType.Int32, a_products_specs_det.Specsheetid);
                database.AddInParameter(dbCommand, "@Specname", DbType.AnsiString, a_products_specs_det.Specname);
                database.AddInParameter(dbCommand, "@Value1", DbType.AnsiString, a_products_specs_det.Value1);
                database.AddInParameter(dbCommand, "@Value2", DbType.AnsiString, a_products_specs_det.Value2);
                database.AddInParameter(dbCommand, "@Value3", DbType.AnsiString, a_products_specs_det.Value3);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_products_specs_det methods
        public virtual void Deletea_products_specs_det(int id)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_products_specs_det_del");
                
                database.AddInParameter(dbCommand, "@Id", DbType.Int32, id);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_products_specs_det methods
        
        public virtual a_products_specs_det Geta_products_specs_det(int id)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_products_specs_det_sel");
                
                database.AddInParameter(dbCommand, "@Id", DbType.Int32, id);
                
                a_products_specs_det a_products_specs_det =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_products_specs_det = Createa_products_specs_detFromReader(reader);
                        reader.Close();
                    }
                }
                return a_products_specs_det;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_products_specs_detList methods
        public virtual a_products_specs_detCollection Geta_products_specs_detList(a_products_specs_detColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_products_specs_det_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_products_specs_detCollection a_products_specs_detCollection = new a_products_specs_detCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_products_specs_det a_products_specs_det = Createa_products_specs_detFromReader(reader);
                        a_products_specs_detCollection.Add(a_products_specs_det);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_products_specs_detCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_products_specs_detCollection Geta_products_specs_detList(a_products_specs_detColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_products_specs_detList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
    }
}